//
//  EditViewController.m
//  Article
//
//  Created by LONG on 16/4/25.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "EditViewController.h"
#import <WXApi.h>
#import "OllTableViewCell.h"
#import "OtherTableViewCell.h"
#import "MateModel.h"

@interface EditViewController ()<UIWebViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UIView *backview;
//@property(nonatomic,weak) UIButton *selectedBtn;

@end

@implementation EditViewController{
    UIWebView *_webview;
    UITableView *_myTableView;
    UILabel *_titlelab;//弹框title
    NSMutableArray *_dataarr;
    NSString *_type;//类型
    NSMutableArray *_numerArr;//广告选择数组
    NSMutableDictionary *_dataId;//广告选择ID
    NSString *_position;//广告的位置 top  bottom
    
    
    UIButton *_cancelbtn;//取消分享
    
    UIView   *_sheraview;//分享
    
    UIButton *_rightbtn;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"文章详情";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"arrow"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    [self.navigationItem.leftBarButtonItem setTintColor:[UIColor whiteColor]];
    
    [self.navigationController.navigationBar setBarTintColor:UIColorFromRGB(MYColor)];
    
    
    if ([WXApi isWXAppInstalled]) {
        _rightbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
        [_rightbtn setTitle:@"分享" forState:UIControlStateNormal];
        [_rightbtn addTarget:self action:@selector(addview) forControlEvents:UIControlEventTouchUpInside];
        [_rightbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _rightbtn.titleLabel.font = [UIFont fontWithName:@"Heiti SC" size:15];
        UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithCustomView:_rightbtn];
        self.navigationItem.rightBarButtonItem = right;
        [self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
    }
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size:18],
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    
    _type = @"banner";
    
    [WXApi registerApp:@"wx9f153fe5ada03660"];
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    _windowurl = [NSString stringWithFormat:@"%@?writing_id=%@&uid=%@",ARTICLEDETAIL_URL,_id,[user objectForKey:@"uid"]];
    
    [self requestTableview];
    [self webview];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(errCode) name:@"errCode" object:nil];
}
- (void)webview{
    
    // NSString *str  = @"http://hmyx.ijiaque.com/app/article/articledetail.html?writing_id=18";
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_windowurl]];
    
    
    _webview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 10)];

    _webview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_webview];
    _webview.delegate = self;
    [_webview loadRequest:request];

    //[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    
}

//分享后的回调
- (void)errCode{

    [self removeView];

    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    
    NSDictionary *dic = @{@"user_token":[user objectForKey:@"token"],
                          @"writing_id":[NSString stringWithFormat:@"%@",self.id]};
    AFHTTPRequestOperationManager *manager = [MyTools initAFHttpManager];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [manager POST:SHARESUCCESS_URL parameters:dic success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        [self.view makeToast:[responseObject objectForKey:@"info"] duration:1.0 position:CSToastPositionCenter];
        
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        if ([MyTools connectedToNetwork] == 0) {
            [self.view makeToast:@"请检查是否联网" duration:1.0 position:CSToastPositionCenter];
        }else{
            [self.view makeToast:@"服务器错误，再试一次" duration:1.0 position:CSToastPositionCenter];
        }

    }];
    
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    NSString *requestString = [[request URL] absoluteString];//获取请求的绝对路径.
    NSArray *components = [requestString componentsSeparatedByString:@":"];//提交请求时候分割参数的分隔符
    
    if ([components count] > 1 && [(NSString *)[components objectAtIndex:0] isEqualToString:@"activity"]) {
        //过滤请求是否是我们需要的.不需要的请求不进入条件
        if ([(NSString *)[components objectAtIndex:1] isEqualToString:@"1"]) {
            _position = @"top";
        }else{
            _position = @"bottom";
        }
        [self pushmessage];
        
        return NO;
    }
    return YES;
}

-(void)pushmessage{
    _numerArr = [NSMutableArray arrayWithCapacity:0];
    _dataId = [[NSMutableDictionary alloc]init];
    
    _window = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    _window.windowLevel = UIWindowLevelAlert+1;
    _window.backgroundColor = [UIColor colorWithWhite:0.5f alpha:0.5f];
    [_window makeKeyAndVisible];//关键语句,显示window
    [self backview];
}
//弹出框
- (UIView *)backview{
    
    if (_backview == nil) {
        _backview = [[UIView alloc]initWithFrame:CGRectMake(0, 40, WIDTH, HEIGHT-100)];
        _backview.backgroundColor = UIColorFromRGB(0xefeff1);
        [_window addSubview:_backview];
        
        _titlelab = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, WIDTH, 20)];
        if ([_position isEqualToString:@"top"]) {
            _titlelab.text = @"顶部还能选择:5个素材";
        }else{
            _titlelab.text = @"底部还能选择:5个素材";
        }
        _titlelab.font = [UIFont systemFontOfSize:15];
        _titlelab.textAlignment = NSTextAlignmentCenter;
        [_backview addSubview:_titlelab];
        
        UIButton *resignbut = [[UIButton alloc]initWithFrame:CGRectMake(0, _backview.frame.size.height-30, WIDTH/2, 30)];
        [resignbut setTitle:@"取消" forState:UIControlStateNormal];
        [resignbut addTarget:self action:@selector(resignWindow) forControlEvents:UIControlEventTouchUpInside];
        resignbut.titleLabel.font = [UIFont systemFontOfSize:14];
        [resignbut setTitleColor:UIColorFromRGB(MYColor) forState:UIControlStateNormal];
        [_backview addSubview:resignbut];
        
        UIButton *returnbut = [[UIButton alloc]initWithFrame:CGRectMake(WIDTH/2, _backview.frame.size.height-30, WIDTH/2, 30)];
        [returnbut setTitle:@"保存" forState:UIControlStateNormal];
        [returnbut addTarget:self action:@selector(returnview) forControlEvents:UIControlEventTouchUpInside];
        returnbut.titleLabel.font = [UIFont systemFontOfSize:14];
        [returnbut setTitleColor:UIColorFromRGB(MYColor) forState:UIControlStateNormal];
        [_backview addSubview:returnbut];
        
        UILabel *xian = [[UILabel alloc]initWithFrame:CGRectMake(0, _backview.frame.size.height-31, WIDTH, 0.5)];
        xian.backgroundColor = UIColorFromRGB(0x666666);
        [_backview addSubview:xian];
        UILabel *xian1 = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH/2, _backview.frame.size.height-28, 0.5, 25)];
        xian1.backgroundColor = UIColorFromRGB(0x666666);
        [_backview addSubview:xian1];
        
        //NSArray *arr = @[@"通栏",@"图文",@"名片",@"二维码"];
//        NSArray *arr = @[@"通栏",@"图文",@"名片"];
//
//        for (int i = 0; i<arr.count; i++) {
//            UIButton *leibut = [[UIButton alloc]initWithFrame:CGRectMake(5+i*(WIDTH-10)/3, 30, (WIDTH-10)/3, 30)];
//            [leibut setTitle:arr[i] forState:UIControlStateNormal];
//            [leibut setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
//            [leibut setTitleColor:UIColorFromRGB(MYColor) forState:UIControlStateSelected];
//            [leibut addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
//            leibut.tag = 350+i;
//            leibut.backgroundColor = [UIColor whiteColor];
//            leibut.titleLabel.font = [UIFont systemFontOfSize:14];
//            if (i == 0) {
//                [self click:leibut];
//            }
//            [_backview addSubview:leibut];
//        }
        
        UIButton *leibut = [[UIButton alloc]initWithFrame:CGRectMake(5, 30, WIDTH-10, 30)];
        [leibut setTitle:@"通栏" forState:UIControlStateNormal];
        [leibut setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
        [leibut setTitleColor:UIColorFromRGB(MYColor) forState:UIControlStateSelected];
        [leibut addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        leibut.tag = 350;
        leibut.backgroundColor = [UIColor whiteColor];
        leibut.titleLabel.font = [UIFont systemFontOfSize:14];
        
        [_backview addSubview:leibut];
        _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 65, WIDTH, _backview.frame.size.height-96)];
        _myTableView.backgroundColor = [UIColor clearColor];
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
        _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        [_myTableView registerNib:[UINib nibWithNibName:@"OllTableViewCell" bundle:nil] forCellReuseIdentifier:@"OllTableViewCell"];
        [_myTableView registerNib:[UINib nibWithNibName:@"OtherTableViewCell" bundle:nil] forCellReuseIdentifier:@"OtherTableViewCell"];
        
        _myTableView.showsVerticalScrollIndicator = NO;
        
        [_backview addSubview:_myTableView];
        
    }
    return _backview;
}
#pragma mark 网络请求

- (void)requestTableview{
    
    _dataarr = [NSMutableArray arrayWithCapacity:0];
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = @{@"page":@"0",
                          @"type":_type,
                          @"user_token":[user objectForKey:@"token"]};
    AFHTTPRequestOperationManager *manager = [MyTools initAFHttpManager];
    //[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [manager POST:ADSLIST_URL parameters:dic success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        //[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        if ([[responseObject objectForKey:@"status"] intValue] == 1) {
            //建立模型
            for (NSDictionary*dic in [responseObject objectForKey:@"data"]) {
                MateModel*model=[[MateModel alloc]init];
                
                [model setValuesForKeysWithDictionary:dic];
                //追加数据
                [_dataarr addObject:model];
                //[_numerArr addObject:@"0"];
            }
        }else{
            [self.view makeToast:[responseObject objectForKey:@"info"] duration:1.0 position:CSToastPositionCenter];
        }
        
        [_myTableView reloadData];
        
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
       // [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        if ([MyTools connectedToNetwork] == 0) {
            [self.view makeToast:@"请检查是否联网" duration:1.0 position:CSToastPositionCenter];
        }else{
            [self.view makeToast:@"服务器错误，再试一次" duration:1.0 position:CSToastPositionCenter];
        }
    }];
}
//素材切换
- (void)click:(UIButton *)btn
{
    NSArray *arr = @[@"banner",@"imgtext",@"vcard",@"tdcode"];
    _type = arr[btn.tag-350];
    
    //self.selectedBtn.selected = NO;
    //btn.selected = YES;
    //self.selectedBtn = btn;
    
    [self requestTableview];
}
//保存素材
- (void)returnview{
    NSString *strId = [[NSString alloc]init];;
    for (NSString *str in _dataId) {
        strId = [strId stringByAppendingFormat:@",%@",[_dataId objectForKey:str]];
    }
    strId = [strId substringWithRange:NSMakeRange(1, strId.length-1)];
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    
    
    NSMutableDictionary *dic = [NSMutableDictionary new];
    [dic setValue:[user objectForKey:@"token"] forKey:@"user_token"];
    [dic setValue:[NSString stringWithFormat:@"%@",_id] forKey:@"writing_id"];
    if ([_position isEqualToString:@"top"]) {
        [dic setValue:[NSString stringWithFormat:@"%@",strId] forKey:@"writing_ads_top"];
        
    }else{
        [dic setValue:[NSString stringWithFormat:@"%@",strId] forKey:@"writing_ads_bottom"];
        
    }
    NSLog(@"%@",dic);
    AFHTTPRequestOperationManager *manager = [MyTools initAFHttpManager];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [manager POST:EDITARTICLE_URL parameters:dic success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        if ([[responseObject objectForKey:@"status"] intValue] == 1) {
            [self resignWindow];
            NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_windowurl]];
            [_webview loadRequest:request];
            
        }else{
            
        }
        NSLog(@"%@",[responseObject objectForKey:@"info"]);
        [_backview makeToast:[responseObject objectForKey:@"info"] duration:1.0 position:CSToastPositionCenter];
        
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        if ([MyTools connectedToNetwork] == 0) {
            [self.view makeToast:@"请检查是否联网" duration:1.0 position:CSToastPositionCenter];
        }else{
            [self.view makeToast:@"服务器错误，再试一次" duration:1.0 position:CSToastPositionCenter];
        }
    }];
}

- (void)resignWindow
{
    [_window resignKeyWindow];
    _window.hidden = YES;
    _window = nil;
    _backview = nil;
}

#pragma mark 分享

- (void)addview{
    
    
    _rightbtn.userInteractionEnabled = NO;
    _cancelbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, WIDTH , HEIGHT)];
    
    _cancelbtn.alpha = 0;
    _cancelbtn.backgroundColor = [UIColor blackColor];
    
    [_cancelbtn addTarget:self action:@selector(removeView) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_cancelbtn];
    
    
    [UIView animateWithDuration:0.3 animations:^{
        
        
        
        _cancelbtn.alpha = 0.6;
        
        _sheraview = [[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT - 180 * MYWIDTH, WIDTH, 180 * MYWIDTH)];
        _sheraview.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_sheraview];
        
        UILabel *titlelab = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, WIDTH/2, 20)];
        titlelab.text = @"分享到";
        titlelab.textColor = UIColorFromRGB(0x333333);
        titlelab.font = [UIFont systemFontOfSize:16];
        [_sheraview addSubview:titlelab];
        
        
        UIButton *wxbtn = [[UIButton alloc]initWithFrame:CGRectMake(15, 35 * MYWIDTH, 50 * MYWIDTH, 50 * MYWIDTH)];
        wxbtn.tag = 1;
        [wxbtn setBackgroundImage:[UIImage imageNamed:@"weixin"] forState:UIControlStateNormal];
        [wxbtn addTarget:self action:@selector(sheraMessage:) forControlEvents:UIControlEventTouchUpInside];
        [_sheraview addSubview:wxbtn];
        
        UIButton *pyqbtn = [[UIButton alloc]initWithFrame:CGRectMake(90 * MYWIDTH, 35 * MYWIDTH, 50 * MYWIDTH, 50 * MYWIDTH)];
        pyqbtn.tag = 2;
        [pyqbtn setBackgroundImage:[UIImage imageNamed:@"pengyouquan"] forState:UIControlStateNormal];
        [pyqbtn addTarget:self action:@selector(sheraMessage:) forControlEvents:UIControlEventTouchUpInside];
        [_sheraview addSubview:pyqbtn];
        
        UILabel *wxlab = [[UILabel alloc]initWithFrame:CGRectMake(5, 85 * MYWIDTH, 70 * MYWIDTH, 20 * MYWIDTH)];
        wxlab.text = @"微信好友";
        wxlab.font = [UIFont systemFontOfSize:11];
        wxlab.textAlignment = NSTextAlignmentCenter;
        wxlab.textColor = UIColorFromRGB(0x666666);
        [_sheraview addSubview:wxlab];
        
        UILabel *pyqlab = [[UILabel alloc]initWithFrame:CGRectMake(80 * MYWIDTH, 85 * MYWIDTH, 70 * MYWIDTH, 20 * MYWIDTH)];
        pyqlab.text = @"朋友圈";
        pyqlab.font = [UIFont systemFontOfSize:12];
        pyqlab.textAlignment = NSTextAlignmentCenter;
        pyqlab.textColor = UIColorFromRGB(0x666666);
        [_sheraview addSubview:pyqlab];
    }];
    
    
}
#pragma mark- 缩放图片
-(UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
    UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize));
    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}
-(void)sheraMessage:(UIButton *)btn{
    
    
    WXMediaMessage *messgae = [WXMediaMessage message];
    messgae.title = _writing_title;
   
    NSLog(@"<><><>%@",_writing_img);
    if (_writing_img.length == 0 ) {
        [messgae setThumbImage:[UIImage imageNamed:@"Icon-120"]];
    }else{
        CGSize size2 = [self getImageFromURL:_writing_img].size;
        if (size2.width>200 || size2.height>200) {
            UIImage *scaleImage = [self scaleImage:[self getImageFromURL:_writing_img] toScale:0.3];
            [messgae setThumbImage:scaleImage];
            
        }else{
            [messgae setThumbImage:[self getImageFromURL:_writing_img]];
            
        }
    }
    
    
    
    WXWebpageObject *webpage = [WXWebpageObject object];
    webpage.webpageUrl = [NSString stringWithFormat:@"%@&share=true",self.windowurl];
    NSLog(@"微信分享:%@",webpage.webpageUrl);
    messgae.mediaObject = webpage;
    
    SendMessageToWXReq *req = [[SendMessageToWXReq alloc]init];
    req.bText = NO;
    req.message = messgae;
    
    if (btn.tag == 1) {
        req.scene = WXSceneSession;
    }else if (btn.tag == 2){
        req.scene = WXSceneTimeline;
    }
    
    [WXApi sendReq:req];
    
    
}
-(UIImage *) getImageFromURL:(NSString *)fileURL {
    //NSLog(@"执行图片下载函数");
    UIImage * result;
    NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
    result = [UIImage imageWithData:data];
    return result;
}
-(void)removeView{
    _rightbtn.userInteractionEnabled = YES;
    [UIView animateWithDuration:0.5 animations:^{
        [_cancelbtn removeFromSuperview];
        [_sheraview removeFromSuperview];
    }];
}

#pragma mark tableView代理

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return _dataarr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"car_cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    }
    if (!(_dataarr.count == 0)) {
        MateModel*model=_dataarr[indexPath.row];
        
        if ([_type isEqualToString:@"banner"]) {
            OllTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OllTableViewCell" forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [cell configModel:model];
            
            cell.imagebut.hidden = YES;
            
            if ([_numerArr containsObject:model.id] == 0) {
                cell.imagebut.hidden = YES;
            }else{
                cell.imagebut.hidden = NO;
            }
            
            if (5-_dataId.count < 1) {
                if ([_numerArr containsObject:model.id] == 1) {
                    cell.userInteractionEnabled = YES;
                }else{
                    cell.userInteractionEnabled = NO;
                }
            }else{
                cell.userInteractionEnabled = YES;
            }
            return cell;
        }
        OtherTableViewCell *cel = [tableView dequeueReusableCellWithIdentifier:@"OtherTableViewCell" forIndexPath:indexPath];
        cel.selectionStyle = UITableViewCellSelectionStyleNone;
        [cel configModel:model];
        
        cel.imagebut.hidden = YES;
        
        if ([_numerArr containsObject:model.id] == 0) {
            cel.imagebut.hidden = YES;
        }else{
            cel.imagebut.hidden = NO;
        }
        if (5-_dataId.count < 1) {
            if ([_numerArr containsObject:model.id] == 1) {
                cel.userInteractionEnabled = YES;
            }else{
                cel.userInteractionEnabled = NO;
            }
        }else{
            cel.userInteractionEnabled = YES;
        }
        return cel;
    }
    
    return cell;
    
}
#pragma mark delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([_type isEqualToString:@"banner"]) {
        return 80*WIDTH/320;
    }
    return 90;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MateModel*model=_dataarr[indexPath.row];
    
    if ([_numerArr containsObject:model.id] == 0) {
        [_numerArr addObject:model.id];
        [_dataId setValue:model.id forKey:model.id];
    }else{
        [_numerArr removeObject:model.id];
        [_dataId removeObjectForKey:model.id];
    }
    [_myTableView reloadData];
    
    if ([_position isEqualToString:@"top"]) {
        _titlelab.text = [NSString stringWithFormat:@"顶部还能选择:%zd个素材",5-_dataId.count];
    }else{
        _titlelab.text = [NSString stringWithFormat:@"底部还能选择:%zd个素材",5-_dataId.count];
    }
    NSLog(@"%@",_dataId);
}

-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    self.tabBarController.tabBar.translucent = YES;
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
-(void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"errCode" object:nil];
    
}
@end
